package com.vma.jifu.backsys.config;


import com.jfinal.config.*;
import com.jfinal.core.JFinal;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.template.Engine;
import com.vma.jifu.backsys.controller.*;
import com.vma.jifu.bizModel.model._MappingKit;

/**
 * Created by chenzui on 2017/5/5.
 */
public class JifuConfig extends JFinalConfig{
    public static void main(String[] args) {
        /**
         * 特别注意：Eclipse 之下建议的启动方式
         */
        JFinal.start("src/main/webapp", 8080, "/", 5);

        /**
         * 特别注意：IDEA 之下建议的启动方式，仅比 eclipse 之下少了最后一个参数
         */
//		 JFinal.start("WebRoot", 8080, "/");
    }
    public void configConstant(Constants me) {
        PropKit.use("a_little_config.txt");
        me.setDevMode(PropKit.getBoolean("devMode", false));
        me.setBaseUploadPath(PathKit.getWebRootPath()+"/temp");

    }

    public void configRoute(Routes me) {
        me.add("index", IndexController.class);
        me.add("offer", OfferController.class);
        me.add("user", UserController.class);
        me.add("order",OrderController.class);
        me.add("cash", CashController.class);
        me.add("pull",PullController.class);
        me.add("conifg",ConfigController.class);
        me.add("staff",StaffController.class);
        me.add("offertype",OfferTypeController.class);
        me.add("common",CommonController.class);
        me.add("ad",AdController.class);
        me.add("system",SystemController.class);
        me.add("file",FileController.class);
        me.add("message",MessageController.class);
        me.add("base",BaseController.class);
    }

    public void configEngine(Engine engine) {

    }

    public void configPlugin(Plugins me) {
        // 配置C3p0数据库连接池插件
        DruidPlugin druidPlugin = createDruidPlugin();
        me.add(druidPlugin);

        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
        // 所有映射在 MappingKit 中自动化搞定
        arp.setShowSql(true);

        _MappingKit.mapping(arp);
        //配置redis
//        RedisPlugin tokenServer = new RedisPlugin("tokenServer", "119.23.246.159",6379);
//        RedisPlugin tokenServer = new RedisPlugin("tokenServer", "119.23.246.159",6379,"MD0ER6gU4esf");

//        me.add(tokenServer);

        me.add(arp);
    }

    /**
     * 配置全局拦截器
     */
    public void configInterceptor(Interceptors me) {

        me.add(new LoginInterceptor());

    }

    /**
     * 配置处理器
     */
    public void configHandler(Handlers me) {

    }

    public static DruidPlugin createDruidPlugin() {
        return new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
    }
}
